<?php
# $Id$
require_once(APP_LIB_DIR . 'Sajax.php');
require_once('utils.inc.php');

function getlist($p='',$search='',$by='1',$s='DESC') { 
    $a = new AddressBookAction();
    parse_str($search,$res);
    return $a->getlist($p,$res,$by,$s); 
}
function lookup($what=''){
    $l = new AddressBookAction();
    return $l->lookup($what);
}
function save($detail='',$id='',$action=''){
    $s = new AddressBookAction();
    parse_str($detail,$res);
    return $s->save($res,$id,$action);
}

sajax_init();
//$sajax_debug_mode = 1;
sajax_export('getlist');
sajax_export('lookup');
sajax_export('save');
sajax_handle_client_request();
$sajax_request_type = 'POST';
require_once('header.php'); 
?>
<script language="JavaScript" type="text/javascript">

<?php sajax_show_javascript();?>

var s = "ASC";
var b = 1;

function page(p) {
    st = $('form1').toQueryString();
    load();
    x_getlist(p,st,b,s,getlist_cb)
}
function sort(by){
    s = (s=="DESC") ? "ASC" : "DESC";
    st = $('form1').toQueryString();
    p = $('pagenum');
    p = (p) ? p.value : 1;
    b = by;
    load();
    x_getlist(p,st,b,s,getlist_cb)
}
function filter(){
    st = $('form1').toQueryString();
    p = 1
    //st = Json.toString(st);
    load();
    x_getlist(p,st,b,s,getlist_cb);
}
function getlist_cb (new_data){
    //alert(new_data)
    data = Json_eval(new_data);
    var fields = [ ["id","ID"],
                   ["stud_no","Student No"],
                   ["firstname","First Name"],
                   ["lastname","Last Name"],
                   ["middlename","Middle Name"],
                   ["type","Type"],
                   ["msisdn","msisdn"]
     //              ["total_loan1","Total Loan"],
       //            ["monthly_payment","Monthly Payment"],
         //          ["balance_loan","Loan Balance"],
           //        ["balance_loan","Loan Balance"],
             //      ["total_cost","Home Beneficiary Total Cost "],
               //    ["monthly_amortization","Monthly Amortization"],
                 //  ["balance_home","Balance "]
		  	
                 ]
    var  extra = [ [true,'id','edit'],
                   [true,'id','del']
                 ]
                 
    $("thetable").innerHTML = data[1]
    $("thetable").innerHTML += mytable(data[0],fields, extra)
}

/*function levels_cb (new_data){
    data = Json_eval(new_data);
    AddToOptionList(data, $('level'), 'id','name')
}*/
function clearOrder(a){
  
         data = $('form2').toQueryString();
         $('myid').value=''
//alert("clearing list of cred");

}
function save () {
    data = $('form2').toQueryString();
    id = $('myid').value
    $('myid').value = ''
    x_save(data,id, function(new_data1){
      Json_eval(new_data1);
      filter();
      show_t()
    });
}
function show_t(){
    if($('thetable').style.display == "none"){
        hide_t('newform','thetable')
        $('altfrm').value = "New Contacts"
    } else {
        hide_t('thetable','newform')
        $('altfrm').value = "Back to List"
    }
    $('form2').reset();
    $('myid').value = ''
}

function edit (id) {
    x_save('',id,'get', function(new_data1){
       d = Json_eval(new_data1);
       $('stud_no').value = d[0]['stud_no'];
       $('firstname').value = d[0]['firstname'];
       $('lastname').value = d[0]['lastname'];
       $('middlename').value = d[0]['middlename'];
       $('email_add').value = d[0]['email_add'];
       $('no').value = d[0]['add_no'];
       $('street').value = d[0]['add_street'];
       $('subd').value = d[0]['add_subdbrgy'];
       $('town').value = d[0]['add_townctry'];
       $('zip').value = d[0]['add_zipcode'];
       $('homenumber').value = d[0]['homenumber'];
       $('type').value = d[0]['type'];
    //   $('total_loan').value = d[0]['total_loan1'];
    //   $('balance_loan').value = d[0]['balance_loan'];
    //   $('monthlypayment').value = d[0]['monthly_payment'];
    //   $('total_cost').value = d[0]['total_cost'];
    //   $('monthly_amortization').value = d[0]['monthly_amortization'];
    //   $('balance_home').value = d[0]['balance_home'];
       $('msisdn').value = d[0]['msisdn'];
       $('myid').value = d[0]['id'];
       //optionSelected($('level'), d[0]['level_id'])
       hide_t('thetable','newform');
    }) 
    return false;
}

function del (id) {
    if (confirm('Are you sure you want to delete this Record?')){
      x_save('',id,'del', function(new_data1){
        Json_eval(new_data1);
        filter();
      })   
    }
}

function load (){
    //$("thetable").empty().addClass('ajax-loading');
    $("thetable").innerHTML = loading;
}

</script>
<link rel="stylesheet" href="<?=WEB_MODULE_DIR?>css/structure2.css" type="text/css" />
<link rel="stylesheet" href="<?=WEB_MODULE_DIR?>css/form2.css" type="text/css" />
<div id="toolbar-box">
  <div class="m">
    <div class="toolbar-list" id="toolbar">
      <!-- TOOL BAR MENU ex:HELP|NEW|EDIT-->
      <!-- END TOOL BAR MENU -->
      <div class="clr"></div>
    </div>
    <div class="pagetitle icon-48-cpanel"><h2><?=$config['version']?></h2></div>
     <!-- [</?=strtoupper($auth['privilege'])?>]-->
  </div>
</div>
<div align="center" class="centermain">
    <table class="adminlist" width="100%">
      <tr>
        <th class="title"><a href="javascript: show_tool('panel');">:: SEARCH PANEL</a></th>
      </tr>
      <tr>
        <td width="40%" valign="top">
        <!-- filter panel -->
          <div id="panel">
            <table class="adminlist" width="100%">
              <tr>
                <td>
                  <form id="form1" class="wufo" action="" method="post" onSubmit="filter();return false;">
                    <ul>
                      <li>
                            <span>
                            <label class="desc">Search Student:</label>
                            </span>
                        <span>
                          <select class="field select" style="width:10em" name="search[searchfield]">
		            <option value="stud_no">Ref. No</option>
		            <option value="firstname">First Name</option>
                            <option value="lastname">Last Name</option>
                            <option value="middlename">Middle Name</option>
                            <option value="msisdn">Mobile Number</option>
                            <option value="type">Type</option>
                          </select>
                        </span>
                        
                        <span>
                          <input class="field text" size="15" name="search[searchtext]" value="" onKeyup="filter()">
                        </span>
                          
                        <span>
                          <input id="saveForm" class="btTxt" type="button" value="Search" onClick="filter()"/>
                          <input class="btTxt" type="button" value="Clear" onClick="this.form.reset();filter()"/>
                          <input id="altfrm" class="btTxt" type="button" value="New Student" onClick="show_t()"/>



                        </span>
                      </li>
                    </ul>

                  </form>

<form enctype="multipart/form-data" action="" method="POST">
<!--<input type="hidden" name="MAX_FILE_SIZE" value="<?=ini_get('upload_max_filesize')?>" />-->
Choose a file to upload: <input name="uploadedfile" type="file" />
<input type="submit" name="import" value="Upload File" />
<input type="submit" name="export" value="Export Users" />
</form>
                </td>
              </tr>
            </table>
          </div>
        <!-- filter panel end -->
        </td>
      </tr>
    </table>
      <form id="form2" method="post" onSubmit="return false;">
        <table class="adminform" width="100%">
          <tr>
            <th class="title">:: SEARCH RESULTS</th>
          </tr>
          <tr>
            <td>
              <div id="thetable"><img src="/mcs/modpub/images/loading_small.gif"/></div>
            </td>
          </tr>
          <tr>
            <td align="center">
              <div id="newform" style="display: none" class="container">
                <input type="hidden" value="" id="myid" />
                <table class="adminform" align="center" width="100%">
                  <tr>
                    <td width="40%" valign="top">
                      <table class="admilist" width="100%">                          
                        <tr>
                          <th colspan="3">PERSONAL DATA</th>
                        </tr>
                        <tr>
                          <td colspan="3">
                            <table class="adminform" width="100%">
                              <tr>
                                <td><b>Reference No.(Student No./ Employee No.)</b></td>
                              </tr>
                              <tr> 
                                <td><input class="field text" id="stud_no" size="20" name="details[stud_no]" value=""></td>
                              </tr>
                            </table>
                          </td>
                        </tr>
                        <tr>
                          <td colspan="3">
                            <table class="adminform" width="100%">
                              <tr>
                                <td><b>NAME</b></td>
                              </tr>
                              <tr> 
                                <td><input class="field text" id="lastname" size="20" name="details[lastname]" value="">Last</td>
                                <td><input class="field text" id="firstname" size="20" name="details[firstname]" value="">First</td>
                                <td><input class="field text" id="middlename" size="20" name="details[middlename]" value="">Middle</td>
                              </tr>
                            </table>
                          </td>
                        </tr>
                        <tr>
                          <td colspan="3">
                            <table class="adminform" width="100%">
                              <tr>
                                <td><b>ADDRESS</b></td>
                                <td><input class="field text" id="no" size="10" name="details[add_no]" value="">No</td>
                                <td><input class="field text" id="street" size="25" name="details[add_street]" value="">Street</td>
                                <td><input class="field text" id="subd" size="25" name="details[add_subdbrgy]" value="">Subdivision/Brgy.</td>
                              </tr>
                              <tr>
                                <td colspan="4">
                                  <table width="100%">
                                    <tr>
                                      <td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
                                      <td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
                                      <td><input class="field text" id="town" size="40" name="details[add_townctry]" value="">Town/ City</td>
                                      <td><input class="field text" id="zip" size="15" name="details[add_zipcode]" value="">Zip code</td>
                                    </tr>
                                  </table>
                                </td>
                              </tr>
                            </table>
                          </td>
                        </tr>
                        <tr>
                          <td colspan="3">
                            <table class="adminform" width="100%">
                              <tr>
                                <td colspan="4"><b>Contact Nos.</b></td>
                              </tr>
                              <tr>
                                <td>Home no.</td>
                                <td><input class="field text" id="homenumber" size="25" name="details[homenumber]" value=""></td>
                                <td>Mobile no.</td>
                                <td><input class="field text" id="msisdn" size="15" name="details[msisdn]" value=""></td>
                              </tr>
                              <tr>
                                <td><b>Email Address</b></td>
                                <td colspan="3"><input class="field text" id="email_add" size="50" name="details[email_add]" value=""></td>
                              </tr>
                              <tr>
                                <td><b>Type</b></td>
                                <td>
                                  <select class="field select" style="width:10em" id="type" name="details[type]">
                                    <option value="">N/A</option>
                                    <option value="student">Student</option>
                                    <option value="employee">Employee</option>
                                  </select>
                                </td>
                              </tr>
                            </table>
                          </td>
                        </tr>
                      </table>
                    </td>
<!--                    <td width="60%" valign="top">
                      <table class="adminform">
                        <tr>
                          <th>SAVINGS INFO.</th>
                        </tr>
                        <tr>
                          <td>
                            <table width="100%">
                              <tr>
                                <td>Total Loan</td>
                                <td><input class="field text" id="total_loan" size="20" name="details[total_loan1]" value="">
                              </tr>
                              <tr>
                                <td>Balance</td>
                                <td><input class="field text" id="balance_loan" size="20" name="details[balance_loan]" value="">
                              </tr>
                              <tr>
                                <td>Monthly Payment</td>
                                <td><input class="field text" id="monthlypayment" size="20" name="details[monthly_payment]" value="">
                              </tr>
                            </table>
                          </td>
                        </tr>
                        <tr>
                          <td>
                            <table class="adminform" width="100%">
                              <tr>
                                <th>HOME BENEFICIARY.</th>
                              </tr>
                              <tr>
                                <td>
                                  <table width="100%">
                                    <tr>
                                      <td>Total Cost</td>
                                      <td><input class="field text" id="total_cost" size="20" name="details[total_cost]" value=""></td>
                                    </tr>
                                    <tr>
                                      <td>Monthly Amortization</td>
                                      <td><input class="field text" id="monthly_amortization" size="20" name="details[monthly_amortization]" value="">
                                    </tr>
                                    <tr>
                                      <td>Balance</td>
                                      <td><input class="field text" id="balance_home" size="20" name="details[balance_home]" value="">
                                   </tr>
                                 </table>
                                </td>
                              </tr>-->
                              <tr>
                                <td>
                                  <input id="saveForm" class="btTxt" type="button" value="Save" onClick="save();"/>
                                  <input id="saveForm" class="btTxt" type="button" value="Clear" onClick="this.form.reset();clearOrder();"/>
<!--                                  <input id="saveForm" class="btTxt" value="Clear" onClick="clearOrders();"/>-->
                                  <input id="saveForm" class="btTxt" type="button" value="Cancel" onClick="this.form.reset();clearOrder();hide_t('newform', 'thetable')"/>
                                </td>
                              </tr>
                            </table>
                          </td>
                        </tr>
                      </table>
                    </td>
                  </tr>
                </table>
              </div>
            </td>
          </tr>
        </table>
      </form>
<script type="text/javascript">
x_getlist(getlist_cb)
</script>
<?php require_once('footer.php'); ?>
